package com.qianchang.microfinance.view.credit.data.facerecoder;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

import com.dm.library.utils.DensityUtil;
import com.qianchang.microfinance.R;


public class SendView extends RelativeLayout {

    public RelativeLayout backLayout, selectLayout;
    private static final String TAG = "SendView";
    private int widthPixels;

    public SendView(Context context) {
        super(context);
        init(context);
    }

    public SendView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public SendView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        LayoutParams params = new LayoutParams(DensityUtil.getScreenWidth(getContext()), DensityUtil.dip2px(getContext(),180f));
        setLayoutParams(params);
        RelativeLayout layout = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.widget_view_send_btn, null, false);
        layout.setLayoutParams(params);
        backLayout = (RelativeLayout) layout.findViewById(R.id.return_layout);
        selectLayout = (RelativeLayout) layout.findViewById(R.id.select_layout);
        addView(layout);
        setVisibility(GONE);

        widthPixels = DensityUtil.px2dip(getContext(),DensityUtil.getScreenWidth(getContext()));
    }


    public void startAnim() {
        setVisibility(VISIBLE);
        AnimatorSet set = new AnimatorSet();
        Log.e(TAG, "startAnim: " + widthPixels);
        set.playTogether(
                ObjectAnimator.ofFloat(backLayout, "translationX", 0, -(widthPixels - 80)),
                ObjectAnimator.ofFloat(selectLayout, "translationX", 0, (widthPixels - 80))
        );
        set.setDuration(500).start();
    }

    public void stopAnim() {
        AnimatorSet set = new AnimatorSet();
        set.playTogether(
                ObjectAnimator.ofFloat(backLayout, "translationX", -(widthPixels - 80), 0),
                ObjectAnimator.ofFloat(selectLayout, "translationX", (widthPixels - 80), 0)
        );
        set.setDuration(500).start();
        setVisibility(GONE);
    }

}
